<template>
  <div class="index">
    <el-container>
      <!-- 顶部 -->
       <el-header>
              <div class="logo">
                <img src="../assets/logo.ec55f206.png" alt="">
              </div>
              <h1>电商后台管理系统</h1>

              <div class="logout">
                欢迎光临~<a href="javascript:" @click="logout">退出</a>
              </div>
       </el-header>
       <el-container>
            <!-- 左侧边栏 -->
           <el-aside width="200px">
               <el-menu  :default-active="actives" unique-opened text-color="#fff" background-color="#545c64"  active-text-color="#ffd04b" router>
                    <el-submenu v-for="itme in datas" :key='itme.id' :index='itme.path'>
                      <template slot="title"><i class="el-icon-location"></i>{{itme.authName}}</template>
                      <el-menu-item  v-for='itme2 in itme.children' :key='itme2.id' :index="itme2.path" >
                           <i class="el-icon-menu"></i>
                           <span slot="title">{{itme2.authName}}</span>
                      </el-menu-item>
                    </el-submenu>
               </el-menu>
           </el-aside>
           <!-- 主体 -->
           <el-main>
             <router-view></router-view>
           </el-main>
       </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data () {
    return {
      datas: []
    }
  },
  created () {
    // console.log(token)
    this.$axios.get('menus').then(res => {
      // console.log(res.data)
      this.datas = res.data
    })
  },
  methods: {
    // 退出登陆
    logout () {
      this.$confirm('亲，您确定要退出登陆吗', '温馨提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 当成功是清楚 token 令牌 并且 跳转到登陆页
        localStorage.removeItem('token')
        this.$router.push('login')
      }).catch(e => {
        console.log(e)
      })
    }
  },
  computed: {
    // 菜单激活
    actives () {
      const { path } = this.$route
      // console.log(path)
      return path.slice(1).split('-')[0]
    }
  }
}
</script>

<style  lang='scss' >
.index,.el-container{
  height: 100%;
}
   .index .el-header{
     background: #d8d8d8;
     display: flex;
     justify-content: space-between;
     padding: 0;
     div{
      width: 220px;
      line-height: 40px;
      padding: 10px;
     }
    .logo {

        text-align: center;
        img{
          height: 40px
        }
     }
     h1{
       flex: 1;
       text-align: center;
       line-height: 60px;
       color: #545c64
     }
     .logout{
       text-align: right;
       font-weight: 700;
       a{
        color: orange;
       }
     }
   }
  //  左侧边栏
   .el-aside{
     background: #545c64;
     .el-menu{
       height: 100%;
       border: none;
     }
     .el-menu-item-group__title:hover{
       background: #303133;
     }
   }
  //  主体
   .el-main{
      background: #ecf0f1;
   }
</style>
